<?php
// +----------------------------------------------------------------------
// | zhanshop-mcp / TestMcpClient.php    [ 2025/8/10 17:44 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2025 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\console;

use zhanshop\client\McpClient;
use zhanshop\console\Command;
use zhanshop\console\Input;
use zhanshop\console\Output;

class TestMcpClient extends Command
{
    protected McpClient $mcpClient;
    public function configure()
    {
        $this->setTitle("MCP连接测试")->useDatabase();
    }

    public function execute(Input $input, Output $output)
    {
        $this->mcpClient = new McpClient('http://127.0.0.1:3000/mcp', '');
        $this->init();
        $this->notificationsInitialized();
        $this->ping();
        $this->promptsList();
        $this->resourcesList();
        $this->callTool();
    }

    protected function init()
    {
        $resp = $this->mcpClient->initialize();
        print_r($resp);
    }

    public function notificationsInitialized()
    {
        $resp = $this->mcpClient->notificationsInitialized();
        print_r($resp);
    }

    public function promptsList()
    {
        $resp = $this->mcpClient->promptsList();
        print_r($resp);
    }

    public function toolsList()
    {
        $resp = $this->mcpClient->toolsList();
        print_r($resp);
    }

    public function resourcesList()
    {
        $resp = $this->mcpClient->resourcesList();
        print_r($resp);
    }

    public function ping()
    {
        $resp = $this->mcpClient->ping();
        print_r($resp);
    }

    public function callTool()
    {
        $resp = $this->mcpClient->callTool('v1/ffmpeg.convert:POST', [
            "file" => "http://cdn.zhanshop.cn/202571/-3281133952.mp4",
            "format" => "mp3"
        ]);
        print_r($resp);
    }
}